import 'dart:async';
import 'dart:math';

import 'package:flutter/foundation.dart';

final aibubbleProvider = AIBubbleProvider();

class AIBubbleProvider extends ChangeNotifier {
  List<String>? aiBubble;

  String bubbleHint = '';
  Timer? _timer;

  changeRandom() {
    _timer?.cancel();
    if (aiBubble?.isEmpty ?? true) {
      bubbleHint = '';
      return null;
    }
    if (aiBubble?.length == 1) {
      bubbleHint = aiBubble?.first ?? '';
      return;
    }
    final index = Random().nextInt(aiBubble?.length ?? 0);
    bubbleHint = aiBubble?[index] ?? '';
    _timer = Timer(Duration(seconds: 3), () {
      bubbleHint = '';
      notifyListeners();
    });
    notifyListeners();
  }
}
